#pragma once
#include "gtest/gtest.h"
#include "TestData/model/QuadShell_OneEle.hpp"
#include "SGFem/Pre/Assembly/Assembly.h"
#include "SGFem/ElementCalculator/Factory/ElementCalculatorFactory.h"
#include "SGFem/ShellSecCalculator/ShellSectionParser.h"
#include "../../Membrane/Tria3SmallDrillMem.h"

using SG::Algebra::Matrix;
using SG::DataStructure::FEM::IsotropicMaterial;
using SG::DataStructure::FEM::ElementTypes;
using SG::DataStructure::FEM::ShellSecMaterialConstant;
using SG::FEMSolver::AssemblyEigen;
using SG::FEMSolver::Element::ShellSectionParser;

class Tria3SmallDrillMemTest : public ::testing::Test
{
public:
    virtual void SetUp() override
    {
        localCoord = Matrix (3, 2, {0, 0,
                                    1, 0,
                                    0, 1,});

        IsotropicMaterial mat;
        mat.m_id=1;
        mat.m_E = 30.0;
        mat.m_nu = 0.3;
        mat.m_G = 1.153846153846154e+01;
        
        ShellSectionParser::CalcCommonCm (mat, 1.0, materialConst);

    }
protected:
    Matrix localCoord;
    ShellSecMaterialConstant materialConst;
};

TEST_F (Tria3SmallDrillMemTest, Tria3SmallDrillMemTest)
{
    // Test data
    Tria3SmallDrillMem memCalc;
    memCalc.Initialize ();

    Matrix Cm;
    materialConst.GetCm (0.5, _OUT Cm);

    auto kmTest = memCalc.ComputeStiffness (localCoord, Cm);

    // Target data
    Matrix kmTarget(9, 9, {  
   1.1133585e+01,   5.3499313e+00,  -4.8076923e-03,  -8.2417582e+00,  -2.8774038e+00,  -4.8076923e-03,  -2.8918269e+00,  -2.4725275e+00,  -4.8076923e-03,
   5.3499313e+00,   1.1133585e+01,   4.8076923e-03,  -2.4725275e+00,  -2.8918269e+00,   4.8076923e-03,  -2.8774038e+00,  -8.2417582e+00,   4.8076923e-03,
  -4.8076923e-03,   4.8076923e-03,   3.2051571e-03,   0.0000000e+00,  -4.8076923e-03,   3.2051282e-03,   4.8076923e-03,   0.0000000e+00,   3.2051282e-03,
  -8.2417582e+00,  -2.4725275e+00,   0.0000000e+00,   8.2417582e+00,   0.0000000e+00,   0.0000000e+00,   0.0000000e+00,   2.4725275e+00,   0.0000000e+00,
  -2.8774038e+00,  -2.8918269e+00,  -4.8076923e-03,   0.0000000e+00,   2.8918269e+00,  -4.8076923e-03,   2.8774038e+00,   0.0000000e+00,  -4.8076923e-03,
  -4.8076923e-03,   4.8076923e-03,   3.2051282e-03,   0.0000000e+00,  -4.8076923e-03,   3.2051571e-03,   4.8076923e-03,   0.0000000e+00,   3.2051282e-03,
  -2.8918269e+00,  -2.8774038e+00,   4.8076923e-03,   0.0000000e+00,   2.8774038e+00,   4.8076923e-03,   2.8918269e+00,   0.0000000e+00,   4.8076923e-03,
  -2.4725275e+00,  -8.2417582e+00,   0.0000000e+00,   2.4725275e+00,   0.0000000e+00,   0.0000000e+00,   0.0000000e+00,   8.2417582e+00,   0.0000000e+00,
  -4.8076923e-03,   4.8076923e-03,   3.2051282e-03,   0.0000000e+00,  -4.8076923e-03,   3.2051282e-03,   4.8076923e-03,   0.0000000e+00,   3.2051571e-03,
     });

    // Check
    ASSERT_TRUE(kmTest == kmTarget);
}